<template>
  <div>
    <list ref="list" :disabled="!$permission.canRead()">
      <template #toolbar-left>
        <el-tooltip content="从诺诺系统获取发票信息更新到选中的发票">
          <el-button :loading="updateLoading" @click="updateInvoiceFromNuoNuo" type="primary">更新开票状态</el-button>
        </el-tooltip>
        <el-button :loading="requestLoading" @click="requestInvoiceToNuonuoByJob" type="primary">诺诺开票</el-button>
      </template>
    </list>
  </div>
</template>

<script>
import list from "@/components/fam/invoice/list";
import curdMixins from "@/mixins/curd";
import api from "@/api/fam/invoice";

export default {
  components: {
    list
  },
  data() {
    return {
      updateLoading: false,
      requestLoading: false
    };
  },
  mixins: [curdMixins],
  created() { },
  methods: {
    updateInvoiceFromNuoNuo() {
      var rows = this.$refs.list.getCheckedRowsWithMessage();
      if (!rows) {
        return;
      }
      var ids = rows.map((item) => item.id);
      this.$confirm("确定要从诺诺系统获取信息更新当前发票吗？", "提示", {
        type: "warning",
      })
        .then(() => {
          this.updateLoading = true;
          api.updateInvoiceFromNuoNuo(ids).then((res) => {
            this.$refs.list.reload();
            this.updateLoading = false;
          });
        })
        .catch(() => { });
    },
    requestInvoiceToNuonuoByJob() {
      var rows = this.$refs.list.getCheckedRowsWithMessage();
      if (!rows) {
        return;
      }
      var ids = rows.map((item) => item.id);
      this.$confirm("确定要向诺诺系统请求开票吗？", "提示", {
        type: "warning",
      })
        .then(() => {
          this.requestLoading = true;
          api.requestInvoiceToNuonuoByJob(ids).then((res) => {
            this.$refs.list.reload();
            this.requestLoading = false;
          });
        })
        .catch(() => { });
    }
  },
};
</script>